<template>
  <el-container class="home-container">
    <el-header class="header">
      <span class="title">后台管理系统</span>
      <div class="header-right">
        <div class="logo">
        <img :src="`http://127.0.0.1:3007/${userInfo.avator}`" alt="" />
      </div>
      <span class="userInfo">{{userInfo.username}}</span>
      <i class="iconfont icon-tuichu" @click="logout"></i>
      </div>
    </el-header>
    <el-container class="bottom-container">
      <el-aside :width="isCollapse ? '64px' : '260px'" class="aside">
        <el-menu
          class="el-menu-vertical-demo"
          background-color="#001529"
          text-color="#fff"
          active-text-color="#FFFFFF"
          unique-opened
          :default-active="this.$router.path"
          :collapse="isCollapse"
          :collapse-transition="false"
          router
        >
          <el-menu-item :index="item.path" v-for="(item) in MenuItem" :key="item.id+1" v-show="item.children.length === 0" >
            <i class="iconfont" :class="item.icon"></i>
            <span slot="title">{{item.rightName}}</span>
          </el-menu-item>
          <el-submenu :index="item.path" v-for="(item) in MenuItem" :key="item.id+2" v-show="item.children.length !== 0">
            <template slot="title">
              <i class="iconfont " :class="item.icon"></i>
              <span>{{item.rightName}}</span>
            </template>
            <el-menu-item :index="i2.path" v-for="(i2) in item.children" :key="i2.id">
              <i class="iconfont" :class="i2.icon"></i>
              <span slot="title">{{i2.rightName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main class="main">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data () {
    return {
      isCollapse: false,
      userInfo: '',
      MenuItem: []
    }
  },
  created () {

  },
  mounted () {
    this.getUserInfo()
  },
  computed: {},
  methods: {
    async getUserInfo () {
      const { data: res } = await this.$http.get('/user/getUserInfo')
      if (res.code !== 200) return this.$message.error('获取用户信息失败！')
      this.userInfo = res.data
      this.getRightMenu()
    },
    logout () {
      localStorage.removeItem('Authorization')
      this.$router.push('/login')
    },
    async getRightMenu () {
      const { data: res } = await this.$http.post('/right/getRightMenu', { id: this.userInfo.id })
      if (res.code !== 200) return this.$message.error(res.msg)
      this.MenuItem = res.data
    }
  }
}
</script>
<style lang="less" scoped>
.home-container {
  // height: 100vh;
  height: 100%;
  // width: 100vh;
  // border: 2px solid red;
  background: #f5f7fe;
  .header {
    background: #0051c8;
    height: 70px !important;
    display: flex;
    align-items: center;
    position: relative;
    .header-right{
      position: absolute;
      right: 20px;
      display: flex;
      align-items: center;
      .userInfo{
        margin-left: 15px;
        color: rgba(255,255,255,.7);
        font-size: 14px;
        cursor: pointer;
      }
      .icon-tuichu{
        margin-left: 20px;
        color: rgba(255,255,255,.7);

        cursor: pointer;
      }
    }
    .logo {

      height: 40px;
      width: 40px;
      border-radius: 50%;
      border: 1px solid #eee;
      background: #fff;
      overflow: hidden;
      box-shadow: 0 0 10px #ddd;

      img {
        width: 100%;
        height: 100%;
      }
    }
    .title {
      font-family: bigtitle;
      color: #fff;
      font-size: 28px;
      line-height: 70px;
      text-align: center;
      margin-left: 20px;
    }
  }
  .bottom-container {
    display: flex;
    // height: 100vh;
    height: calc(100% - 60px);
    overflow: hidden;
    .aside {
      background: #00192f;
      widows: 260px;
      // height: 100vh;
      overflow: auto;
      height: 100%;
      .toggle-button {
        color: #fff;
        display: flex;
        justify-content: flex-end;
        padding-right: 20px;
        cursor: pointer;
      }
    }
    .main {
      width: calc(100% - 200px);
    }
  }
}
</style>
<style lang="less">
.el-menu-item i,.el-submenu__title i{
  margin-right: 10px;
}
</style>
